export interface SDKOptions {
    clientId: string
    clientSecret: string
    requestTimeout: number
    authServerIp: string
    authServerPort: number
    authServerSsl: boolean
    proxyPath: string
    loginRedirectUri: string
    dev: boolean
    tokenPersistence: boolean
    heartbeatIp: string,
    heartbeatPort: number,
    heartbeatPath: string
    terminalType: string
    logoutTogether: boolean
    appCode: string
}

export interface GetApiRespHeaderOptions {
    getApiRespHeaders?: string[]
}

export interface GetApiRespHeaderResult {
    respHeaders: Record<string, string>
}

export interface OAuthTokenOptions extends GetApiRespHeaderOptions {
    grantType: string
    parameters: Record<string, any>
}

export interface SSOLoginOptions {
    loginPageCode?: string
    state?: Record<string, any>
}

export type SSOLoginState = Record<string, any> | boolean

export interface FailTokenEndpointResp {
    error: string
    error_description: string
}

export interface SuccessTokenEndpointResp {
    access_token: string
    expires_in: number
    refresh_token: string
    additionalInformation: Record<string, any>
}

export type TokenEndpointResp = FailTokenEndpointResp | SuccessTokenEndpointResp

export interface GrantTokenResult extends GetApiRespHeaderResult {
    result: TokenEndpointResp
}

export interface AuthClient {

    setLogoutHook(hook:LogoutHook):void

    ssoLogin(ssoLoginOptions?: SSOLoginOptions): SSOLoginState

    ssoLogout(redirectUri?: string): Promise<void>

    grantToken(oauthTokenOptions: OAuthTokenOptions): Promise<GrantTokenResult>

    accessToken():string;

    refreshToken():Promise<GrantTokenResult>

}

export type LogoutHook = (local: boolean) => string | void

export interface OnlineSessionInfo{
    id: string

    accountId: string

    appCode: string

    //ip 区分终端不可靠，手机端ip为基站在有限ip池内分配
    ip: string

    terminal: string

    terminalType: string

    heartbeatInterval: number

    activeTime: number
}
export interface Message<T> {
    type: string,
    timestamp: number,
    body?: T
}

export interface RespPayload<T>{
    code: number
    data: T
    msg: string
}